package com.fjt.book_pay.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fjt.book_pay.pojo.P_Record;
import com.fjt.book_pay.pojo.P_User;
import com.fjt.book_pay.service.P_RecordService;

@Controller
public class P_RecordController {
	private P_RecordService p_RecordService;

	public P_RecordService getP_RecordService() {
		return p_RecordService;
	}
	@Resource(name="p_recordservice")
	public void setP_RecordService(@RequestBody P_RecordService p_RecordService) {
		this.p_RecordService = p_RecordService;
	}
	
	@RequestMapping("/record/onerecord")
	@ResponseBody
	public ModelAndView selectOneRecord(@RequestBody P_Record p_Record){
		Map<String, Object> map=new HashMap<String, Object>();
		map=p_RecordService.selectMyRecord(p_Record);
		ModelAndView modelView=new ModelAndView();  
    	modelView.addAllObjects(map);  
    	System.out.println("/p_user/onerecor");
    	return modelView;
	}
	@RequestMapping("/record/allrecord")
	@ResponseBody
	public ModelAndView selectAllMyRecord(@RequestBody P_User p_user,HttpServletRequest request){
		System.out.println(p_user.getPay_name());
		Map<String, Object> modelMap=new HashMap<String, Object>();
		ModelAndView modelView=new ModelAndView(); 
    	HttpSession session=request.getSession();
    	String username=(String)session.getAttribute("username");
    	if(username!=null){
    		p_user.setPay_name(username);
    		modelMap=p_RecordService.selectUserAllRecord(p_user);
        	modelView.addAllObjects(modelMap);  
        	System.out.println("/p_user/allrecord");
        	return modelView;
    	}else{
    		modelMap.put("code", 0);
    		modelMap.put("result", "登录失效，请重新登录！");
    		modelView.addAllObjects(modelMap);
    		
    		System.out.println("/p_user/allrecord no session");
    		return modelView;
    	}
		
	}
	
}
